//
//  UCDatePickerSetting.swift
//  UICreate
//
//  Created by 范晓鑫 on 2021/10/27.
//

import UIKit

extension UCSetting where TargetType: UIDatePicker {
    /// 显示模式
    public static func mode(_ mode: UIDatePicker.Mode) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.datePickerMode = mode
        })
    }
    /// 地区
    public static func locale(_ locale: Locale?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.locale = locale
        })
    }
    /// 日历
    public static func calendar(_ calendar: Calendar?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.calendar = calendar
        })
    }
    /// 时区
    public static func timeZone(_ timeZone: TimeZone?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.timeZone = timeZone
        })
    }
    /// 日期时间
    public static func date(_ date: Date) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.date = date
        })
    }
    /// 最小日期时间
    public static func min(_ min: Date?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.minimumDate = min
        })
    }
    /// 最大日期时间
    public static func max(_ max: Date?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.maximumDate = max
        })
    }
    /// countDownDuration
    public static func count(_ interval: TimeInterval) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.countDownDuration = interval
        })
    }
    /// minuteInterval
    public static func min(interval: Int) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.minuteInterval = interval
        })
    }
    @available(iOS 13.4, *)
    public static func preferred(style: UIDatePickerStyle) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.preferredDatePickerStyle = style
        })
    }
    @available(iOS 15.0, *)
    public static func rounds(min enabled: Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.roundsToMinuteInterval = enabled
        })
    }
}
